﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms.Design;

namespace APP.HELPER.Utils.CustomizeToolbox
{
    public class RecessEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            UITypeEditorEditStyle result;
            if (context != null)
            {
                result = UITypeEditorEditStyle.DropDown;
            }
            else
            {
                result = base.GetEditStyle(context);
            }
            return result;
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            object result;
            if (context != null && provider != null)
            {
                IWindowsFormsEditorService windowsFormsEditorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (windowsFormsEditorService != null)
                {
                    RecessEditorControl recessEditorControl = new RecessEditorControl(windowsFormsEditorService);
                    recessEditorControl.Recess = (int)value;
                    windowsFormsEditorService.DropDownControl(recessEditorControl);
                    result = recessEditorControl.Recess;
                    return result;
                }
            }
            result = base.EditValue(context, provider, value);
            return result;
        }
    }
}
